import {ref, Ref} from "vue"
import {generateVerifyCode} from "@/util"

interface VerifyCodeReturn {
    verifyCode: Ref<string[]>
    setVerifyCode: () => void
}

export function useVerifyCode(): VerifyCodeReturn {
    const verifyCode = ref<string[]>(generateVerifyCode())

    function setVerifyCode() {
        verifyCode.value = generateVerifyCode()
    }

    return {
        verifyCode,
        setVerifyCode
    }
}

interface InitReturn {
    account: Ref<string>
    password: Ref<string>
    rePassword: Ref<string>
    submitCode: Ref<string>
}

export function useInit(): InitReturn {
    const account = ref("")
    const password = ref("")
    const rePassword = ref("")
    const submitCode = ref("")

    return {
        account,
        password,
        rePassword,
        submitCode
    }
}

interface UseInitLoginReturn {
    mobile: Ref<string>
    password: Ref<string>
    code: Ref<string>
    checkStatus: () => string
}

export function useInitLogin(): UseInitLoginReturn {
    const mobile = ref<string>("")
    const password = ref<string>("")
    const code = ref<string>("")

    function checkStatus() {
        if (mobile.value === "" || mobile.value.length < 11) {
            return "手机号输入错误"
        } else if (password.value === "" || password.value.length < 5) {
            return "密码输入错误"
        }
        return ""
    }

    return {
        mobile,
        password,
        code,
        checkStatus
    }
}